package demo1;

class Animal{
    public String name;
    public int age;
    public String color;

    static {
        System.out.println("Animal::static{}");
    }

    {
        System.out.println("Animal::{}");
    }

    public Animal(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
        System.out.println("Animal(String name, int age, String color)");
    }

    public void eat(){
        System.out.println(name+"正在吃饭");
    }
}

class Dog extends Animal{

    static {
        System.out.println("Dog::static{}");
    }

    {
        System.out.println("Dog::{}");
    }

    public Dog(){
        //super()在子类构造方法中只能出现一次 并且不能和this同时出现
        super("haha",10,"黄色");
        System.out.println("Dog()");
    }

    public void bark(){
        System.out.println(name+"正在汪汪汪");
    }
}

class Cat extends Animal{

    static {
        System.out.println("Cat::static{}");
    }

    {
        System.out.println("Cat::{}");
    }

    //当父类无构造方法时，子类也会有一个默认的构造方法
    //相反 如果父类有构造方法，子类必须调用那个存在的构造方法
    /*public Cat(String name,int age,String color){
        super(name,age,color);
    }*/

    //快捷键直接有，都不用选
    public Cat(String name, int age, String color) {
        //这两行顺序不可以调换，super必须在第一行
        super(name, age, color);
        System.out.println("Cat(String name, int age, String color)");
    }

    public void miaomiao(){
        System.out.println(name+"正在喵喵喵");
    }
}

public class test2 {

    public static void main(String[] args) {
        //1.父类和子类的静态先执行 2.父类的实例 父类的构造 3.子类的实例，子类的构造方法
        //4.静态的只执行一次
        Dog dog1=new Dog();
        System.out.println("===============");
        Dog dog2=new Dog();
    }

    public static void main2(String[] args) {
        Dog dog=new Dog();
        System.out.println("===============");
        Cat cat=new Cat("小花",2,"白色");
    }

    public static void main1(String[] args) {
        //先构造父类，再是子类
        Dog dog=new Dog();
        dog.eat();
        dog.bark();
        System.out.println("===============");
        Cat cat=new Cat("小花",2,"白色");
        cat.eat();
        cat.miaomiao();
    }
}
